/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.Transient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 *
 * @author ronald
 */
@Entity
@Table(name = "period_payment_laundry")
public class PeriodPaymentLaundry  extends BaseObject {

    private static final long serialVersionUID = 1L;
    private Long id;
    private Float initAmount;
    private Float endAmount;
    private Float discount;
    private Date initDate;
    private Date endDate;
    private Boolean closed;
    private Laundry laundry;
    private List<LaundryRequest> laundryRequestList;
    private List<LaundryPayment> laundryPaymentList;

    @Column(name="end_amount")
    public Float getEndAmount() {
        return endAmount;
    }

    public void setEndAmount(Float endAmount) {
        this.endAmount = endAmount;
    }

    @Temporal(javax.persistence.TemporalType.DATE)
    @Column(name="end_date", length=50)
    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_period_payment_laundry", unique=true, nullable=false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name="init_amount")
    public Float getInitAmount() {
        return initAmount;
    }

    public void setInitAmount(Float initAmount) {
        this.initAmount = initAmount;
    }

    @Temporal(javax.persistence.TemporalType.DATE)
    @Column(name="init_date", length=50)
    public Date getInitDate() {
        return initDate;
    }

    public void setInitDate(Date initDate) {
        this.initDate = initDate;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id_laundry", nullable = false)
    public Laundry getLaundry() {
        return laundry;
    }

    public void setLaundry(Laundry laundry) {
        this.laundry = laundry;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "periodPaymentLaundry")
    public List<LaundryRequest> getLaundryRequestList() {
        return laundryRequestList;
    }

    public void setLaundryRequestList(List<LaundryRequest> laundryRequestList) {
        this.laundryRequestList = laundryRequestList;
    }

    @Column(name="closed")
    public Boolean getClosed() {
        return closed;
    }

    public void setClosed(Boolean closed) {
        this.closed = closed;
    }
    
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "periodPaymentLaundry")
    public List<LaundryPayment> getLaundryPaymentList() {
        return laundryPaymentList;
    }

    public void setLaundryPaymentList(List<LaundryPayment> laundryPaymentList) {
        this.laundryPaymentList = laundryPaymentList;
    }

    @Column(name="discount")
    public Float getDiscount() {
        return discount;
    }

    public void setDiscount(Float discount) {
        this.discount = discount;
    }

    @Transient
    public String getStringInitDateEndDate(){
        return initDate+" - "+endDate;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PeriodPaymentLaundry other = (PeriodPaymentLaundry) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.initAmount != other.initAmount && (this.initAmount == null || !this.initAmount.equals(other.initAmount))) {
            return false;
        }
        if (this.endAmount != other.endAmount && (this.endAmount == null || !this.endAmount.equals(other.endAmount))) {
            return false;
        }
        if (this.initDate != other.initDate && (this.initDate == null || !this.initDate.equals(other.initDate))) {
            return false;
        }
        if (this.endDate != other.endDate && (this.endDate == null || !this.endDate.equals(other.endDate))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 37 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 37 * hash + (this.initAmount != null ? this.initAmount.hashCode() : 0);
        hash = 37 * hash + (this.endAmount != null ? this.endAmount.hashCode() : 0);
        hash = 37 * hash + (this.initDate != null ? this.initDate.hashCode() : 0);
        hash = 37 * hash + (this.endDate != null ? this.endDate.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
         return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append(this.getId())
                   .append(this.initAmount).append(this.endAmount).append(this.initDate)
                   .append(this.endDate)
                   .toString();
    }
}
